import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

export const constantRoutes = [
  // {
  //   path: '/redirect',
  //   component: Layout,
  //   hidden: true,
  //   children: [
  //     {
  //       path: '/redirect/:path(.*)',
  //       component: () => import('@/views/redirect/index')
  //     }
  //   ]
  // },
  {
    path: '/login',
    component: () => import('@/views/Login.vue'),
    hidden: true,
    meta: {
      title: '登录后台管理系统'
    }
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true,
    meta: {
      title: '404找不到网页'
    }
  },
 
  // {
  //   path: '/401',
  //   component: () => import('@/views/error-page/401'),
  //   hidden: true
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/dashboard',
  //   children: [
  //     {
  //       path: 'dashboard',
  //       component: () => import('@/views/dashboard/index'),
  //       name: 'Dashboard',
  //       meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
  //     }
  //   ]
  // },
  // {
  //   path: '/profile',
  //   component: Layout,
  //   redirect: '/profile/index',
  //   hidden: true,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/profile/index'),
  //       name: 'Profile',
  //       meta: { title: 'Profile', icon: 'user', noCache: true }
  //     }
  //   ]
  // }
]


export const asyncRoutes = [{
  path: '/',
  component: Home,
  children: [
    // {
    //   path: '/',
    //   name: 'Index',
    //   component: () => import('../components/Index.vue'),
    //   meta: {
    //     requireAuth: true, //需要加校检判断的路由
    //     title: '首页'
    //   }
    // },
    {
      path: '/',
      redirect: '/picture',
      name: 'Index',
      component: () => import('../components/account/Picture.vue'),
      meta: {
        requireAuth: true, //需要加校检判断的路由
        title: '首页'
      }
    },
    {
      path: '/picture',
      name: 'picture',
      component: () => import('../components/account/Picture.vue'),
      meta: {
        requireAuth: true, //需要加校检判断的路由
        title: '图片管理',
        role:['admin','operator']
      }
    },
    {
      path: '/icon',
      name: 'icon',
      component: () => import('../components/account/Icon.vue'),
      meta: {
        requireAuth: true, //需要加校检判断的路由
        title: '图标管理',
        role:['admin','operator']
      }
    },
    {
      path: '/data',
      name: 'data',
      component: () => import('../components/account/Data.vue'),
      meta: {
        requireAuth: true, //需要加校检判断的路由
        title: '数据查询',
        role:['admin','operator']
      }
    },
    {
      path: '/category',
      name: 'category',
      component: () => import('../components/account/Category.vue'),
      meta: {
        requireAuth: true, //需要加校检判断的路由
        title: '分类管理',
        role:['admin','operator']
      }
    },
    {
      path: '/tag',
      name: 'tag',
      component: () => import('../components/account/Tag.vue'),
      meta: {
        requireAuth: true, //需要加校检判断的路由
        title: '标签管理',
        role:['admin','operator']
      }
    },
    {
      path: '/back',
      name: 'back',
      component: () => import('../components/account/Back.vue'),
      meta: {
        requireAuth: true,
        title: '后台数据',
        role:['admin','operator']
      }
    },
    {
      path: '/userList',
      name: 'userList',
      component: () => import('../components/account/userList.vue'),
      meta: {
        requireAuth: true,
        title: '用户列表',
        role:['admin','operator']
      }
    },
    {
      path: '/authority',
      name: 'authority',
      component: () => import('../components/account/Authority.vue'),
      meta: {
        requireAuth: true,
        title: '运营者管理',
        role:['admin']
      }
    },
    {
      path: '/bannerConfig',
      name: 'bannerConfig',
      component: () => import('../components/configPages/bannerConfig.vue'),
      meta: {
        requireAuth: true, //需要加校检判断的路由
        title: 'banner位配置',
        role:['admin','operator']
      }
    },
    {
      path: '/searchConfig',
      name: 'searchConfig',
      component: () => import('../components/configPages/searchConfig.vue'),
      meta: {
        requireAuth: true,
        title: '搜索位配置',
        role:['admin','operator']
      }
    },
    {
      path: '/hotConfig',
      name: 'hotConfig',
      component: () => import('../components/configPages/hotConfig.vue'),
      meta: {
        requireAuth: true,
        title: '热门专题位配置',
        role:['admin','operator']
      }
    },
    {
      path: '/TopicConfig',
      name: 'TopicConfig',
      component: () => import('../components/configPages/TopicConfig.vue'),
      meta: {
        requireAuth: true,
        title: '专题位配置',
        role:['admin','operator']
      }
    },
    {
      path: '/suggestConfig',
      name: 'suggestConfig',
      component: () => import('../components/configPages/suggestConfig.vue'),
      meta: {
        requireAuth: true,
        title: '推荐位配置',
        role:['admin','operator']
      }
    },
    {
      path: '/task',
      name: 'Task',
      component: () => import('../components/account/Task.vue'),
      meta: [{
        title: '图片管理'
      }, {
        title: '我的任务'
      }]
    }
  ]
}]

// const routes = [{
//     path: '/',
//     component: Home,
//     children: [{
//         path: '/',
//         name: 'Index',
//         component: () => import('../components/Index.vue'),
//         meta: {
//           requireAuth: true, //需要加校检判断的路由
//           title: '首页'
//         }
//       },
//       {
//         path: '/picture',
//         name: 'picture',
//         component: () => import('../components/account/Picture.vue'),
//         meta: {
//           requireAuth: true, //需要加校检判断的路由
//           title: '图片管理'
//         }
//       },
//       {
//         path: '/data',
//         name: 'data',
//         component: () => import('../components/account/Data.vue'),
//         meta: {
//           requireAuth: true, //需要加校检判断的路由
//           title: '数据查询'
//         }
//       },
//       {
//         path: '/category',
//         name: 'category',
//         component: () => import('../components/account/Category.vue'),
//         meta: {
//           requireAuth: true, //需要加校检判断的路由
//           title: '分类管理'
//         }
//       },
//       {
//         path: '/tag',
//         name: 'tag',
//         component: () => import('../components/account/Tag.vue'),
//         meta: {
//           requireAuth: true, //需要加校检判断的路由
//           title: '分类管理'
//         }
//       },
//       {
//         path: '/back',
//         name: 'back',
//         component: () => import('../components/account/Back.vue'),
//         meta: {
//           requireAuth: true,
//           title: '后台数据'
//         }
//       },
//       {
//         path: '/authority',
//         name: 'authority',
//         component: () => import('../components/account/Authority.vue'),
//         meta: {
//           requireAuth: true,
//           title: '后台权限'
//         }
//       },
//       {
//         path: '/bannerConfig',
//         name: 'bannerConfig',
//         component: () => import('../components/configPages/bannerConfig.vue'),
//         meta: {
//           requireAuth: true, //需要加校检判断的路由
//           title: 'banner配置'
//         }
//       },
//       {
//         path: '/searchConfig',
//         name: 'searchConfig',
//         component: () => import('../components/configPages/searchConfig.vue'),
//         meta: {
//           requireAuth: true,
//           title: '搜索配置'
//         }
//       },
//       {
//         path: '/hotConfig',
//         name: 'hotConfig',
//         component: () => import('../components/configPages/hotConfig.vue'),
//         meta: {
//           requireAuth: true,
//           title: '热门配置'
//         }
//       },
//       {
//         path: '/suggestConfig',
//         name: 'suggestConfig',
//         component: () => import('../components/configPages/suggestConfig.vue'),
//         meta: {
//           requireAuth: true,
//           title: '热门配置'
//         }
//       },
//       {
//         path: '/task',
//         name: 'Task',
//         component: () => import('../components/account/Task.vue'),
//         meta: [{
//           title: '图片管理'
//         }, {
//           title: '我的任务'
//         }]
//       }
//     ]
//   },
//   {
//     path: '/login',
//     name: 'Login',
//     component: () => import('../views/Login.vue')
//   }
// ]

// const router = new VueRouter({
//   routes,
//   mode: 'history' //去掉url中的#
// })

const createRouter = () => new VueRouter({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router